.SUFFIXES: .f90

#F90 = mpif90
F90 = mpiifort
#INTEL = -L/u/local/intel/11.1/openmpi/1.4.2/lib -L/u/local/compilers/intel/11.1/072/mkl/lib/em64t -L/u/local/compilers/intel/11.1/072/lib/intel64 -lmkl_solver_lp64 -Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread
#INTEL = -L/u/local/compilers/intel-cs/2013.0.028/composer_xe/compiler/lib/intel64 -L/u/local/compilers/intel-cs/2013.0.028/composer_xe/mkl/lib/intel64 -Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread
INTEL = -Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -qopenmp -lpthread 
#INTEL = -L/u/local/apps/intel/mkl/current/lib/em64t -lmkl_lapack -lmkl_em64t -lguide -lpthread
#INTEL = -L/u/local/apps/lapack/current/LAPACK -llapack
#-L/u/local/lib -lmkl_lapack -lmkl_ia32 -static -openmp
#FFLAGS = -xW -O3 -ipo  -L/usr/lib -L/usr/local/vni/CTT6.0/lib/lib.intel32
#FFLAGS_PFM = -L/usr/lib -L/usr/local/vni/CTT6.0/lib/lib.intel32
FFLAGS = -O3 -L/usr/local/lib64 -L/u/local/
#FFLAGS_PFM = -L/u/local/ -L/usr/local/lib/
FFLAGS_PFM = -L/u/local/ -L/usr/local/lib64 -L/usr/local/lib

OBJ90 = main.f90 commonvars.f90 prob_ic_emax.f90 emaxfun.f90 probemax.f90 mayordecision_minim.f90 notmayordecision.f90 \
	vfunapprox_age.f90 vfunapprox_age_q.f90 vfunapprox_age_steal.f90 vfunapprox_age_steal_q.f90 vfunapprox_q.f90 \
        vfunapprox_steal.f90 vfunapprox_steal_q.f90 vfunapprox_ability.f90 vfunapprox_ability_q.f90 \
	vfunapprox_ability_steal.f90 vfunapprox_ability_steal_q.f90 zeroin.f90 simulatemun.f90 moments.f90 fcn.f90 utilfun.f90 utilfun_mayor.f90 \
         prodfunc.f90 dprodfunc.f90 mpi_simann.f90 wage_pastmayor.f90 read_ini_data.f90 fine_fun.f90 \
	olsreg.f90 ivreg.f90 objfcn.f90 mpi_minim.f90 nrutil.f90 random.f90 pnorm.f90 hybrd1.f90 hybrd.f90\
	rmultinomial.f90 statistics.f90 mayorsolution.f90 mayorsolution0.f90 pastmayorsolution.f90 set_policy_vars.f90 \
	fcn_mayor.f90 objfcn_mayor.f90 objfcn_mayor0.f90 objfcn_pmayor.f90 mpi_simann_mayor.f90 \
	standarderrors_SMM.f90 truncated_normal.f90

mayor: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor.exe

mayor1: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor1.exe

mayor2: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor2.exe

mayor3: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor3.exe

mayor4: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor4.exe

mayor5: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor5.exe

mayor6: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor6.exe

mayor7: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor7.exe

mayor8: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor8.exe

mayor9: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor9.exe

mayor10: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor10.exe

mayor11: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor11.exe

mayor12: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor12.exe

mayor13: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor13.exe

mayor14: $(OBJ90)
	$(F90)  $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor14.exe

mayor15: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor15.exe

mayor16: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor16.exe

mayor17: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor17.exe

mayor18: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor18.exe

mayor19: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor19.exe

mayor20: $(OBJ90)
	$(F90) $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor20.exe

mayor21: $(OBJ90)
	$(F90) -traceback $(FFLAGS) $(INTEL) $(OBJ90) $(AUXFILES) -o mayor21.exe

debug: $(OBJ90)
	$(F90) -g -check bounds -traceback $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug.exe

debug1: $(OBJ90)
	$(F90) -g -check bounds -traceback $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug1.exe

debug2: $(OBJ90)
	$(F90) -g -check bounds -traceback $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug2.exe

debug3: $(OBJ90)
	$(F90) -g -check bounds -traceback $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug3.exe

debug4: $(OBJ90)
	$(F90) -g -check bounds -traceback -check all $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug4.exe

debug5: $(OBJ90)
	$(F90) -g -check bounds -warn -traceback -checkall -fp-stack-check  -check uninit -ftrapuv -debug all -ffpe-trap=zero,invalid,overflow,underflow -debug extended $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug5.exe

debug6: $(OBJ90)
	$(F90) -g -check bounds -warn -traceback -checkall -fp-stack-check  -check uninit -ftrapuv -debug all -ffpe-trap=zero,invalid,overflow,underflow -fpe0 -init=snan,arrays -debug extended $(FFLAGS_PFM) $(INTEL) $(OBJ90) $(AUXFILES) -o debug6.exe

clean:
	rm *.o *.il *.mod

module: 
	$(F90) $(FFLAGS) -c commonvars.f90 mpi_simann.f90 mpi_simann_mayor.f90 nrutil.f90 random.f90 statistics.f90 mpi_minim.f90 tn.f90

#possible options: -check all
#make clean; make module; make modulelib; make mayor
#debug: /opt/intel/idb/9.0/bin/idb -gdb -fullname ./debug.exe -g -check bounds -traceback  -ftrapuv -fpe -warn
